define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'media/replace/index' + location.search,
                    add_url: 'media/replace/add',
                    del_url: 'media/replace/del',
                    multi_url: 'media/replace/multi',
                    import_url: 'media/replace/import',
                    table: 'media_replace',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'drama_id', title: __('Drama_id')},
                        {field: 'old_media_id', title: __('Old_media_id')},
                        {field: 'new_media_id', title: __('New_media_id')},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4'),"5":__('Status 5'),"6":__('Status 6'),"7":__('Status 7')}, formatter: Table.api.formatter.status},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                        buttons: [
                            {
                                name: 'ajax',
                                text: __('提审剧情'),
                                title: __('提审剧情'),
                                classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                icon: 'fa fa-magic',
                                url: 'media/replace/submitreplacedramamedias?media_replace_id={ids}',
                                confirm: '确认提审剧情',
                                success: function (data, ret) {
                                    Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                    //如果需要阻止成功提示，则必须使用return false;
                                    // return false;
                                },
                                error: function (data, ret) {
                                    console.log(data, ret);
                                    Layer.alert(ret.msg);
                                    return false;
                                }
                            },
                            {
                                name: 'ajax',
                                text: __('查询提审状态'),
                                title: __('查询提审状态'),
                                classname: 'btn btn-xs btn-info btn-magic btn-ajax',
                                icon: 'fa fa-magic',
                                url: 'media/replace/getmedia?media_replace_id={ids}',
                                confirm: '确认查询提审状态',
                                success: function (data, ret) {
                                    Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                    //如果需要阻止成功提示，则必须使用return false;
                                    // return false;
                                },
                                error: function (data, ret) {
                                    console.log(data, ret);
                                    Layer.alert(ret.msg);
                                    return false;
                                }
                            },
                            {
                                name: 'ajax',
                                text: __('替换剧情'),
                                title: __('替换剧情'),
                                classname: 'btn btn-xs btn-danger btn-magic btn-ajax',
                                icon: 'fa fa-magic',
                                url: 'media/replace/replacedramamedia?media_replace_id={ids}',
                                confirm: '确认替换剧情',
                                success: function (data, ret) {
                                    Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                    //如果需要阻止成功提示，则必须使用return false;
                                    // return false;
                                },
                                error: function (data, ret) {
                                    console.log(data, ret);
                                    Layer.alert(ret.msg);
                                    return false;
                                }
                            },
                        ], formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
